package xyz.hujf.project.collect.SDF;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @author Hujf
 * @title: TestSimpleDateFormat2
 * @date 2021-05-03 20:29
 * @description: TODO
 */
public class TestSimpleDateFormat2 {

    static ThreadLocal<DateFormat> sdf = new ThreadLocal<DateFormat>(){
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }
    };

    public static void main(String[] args) {
        for(int i=0;i<10;i++){
            Thread thread = new Thread(()->{
                try {
                        System.out.println(sdf.get().parse("2021-01-12 15:17:39"));
                } catch (ParseException e) {
                    e.printStackTrace();
                }finally {
                    sdf.remove();
                }
            });
            thread.start();
        }
    }
}
